<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<style type="text/css"> 
.msg{float:left; line-height:1.5em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style> 
<s:url value="/images" var="imgPath"/>
<s:url value="/docs/givebouns_example.csv" var="docUrl"/>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script language="javascript">
	$().ready( function() {
		$('#startDate').datepick({minDate: null, showOn: 'both', 
	    	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		$('#expireDate').datepick({minDate: new Date(), showOn: 'both', 
		   	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,beforeShow:customRange,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		function customRange (){
			var startDt = $('#startDate').val(); //起始日
			var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
			return {minDate:endDt}; 
		}
    	$("#saveData").click(function(){
        	$("#uploadFileName").val($("#giveBonusUpload").val());
        	if ( validateData() )
        		$("#formObj").submit();
    	});
    	if("${giveBounsResult}" == "wrong_format"){
			$("#resText").html('格式错误');
			$("#resText").show();
		}
    	if("${giveBounsResult}" == "budget_null"){
			$("#budgetText").html('请选取预算归属');
			$("#budgetText").show();
		}
	});	
	function validateData(){
		var isCorrect = true;
		if ( $("#name").val() == "" ){
			alert("请输入名称");
			isCorrect = true;
		}
		if ( $("#description").val() == "" ){
			alert("请输入叙述");
			isCorrect = false;
		}
		if ( $("#startDate").val() == "" ){
			alert("请输入期间 起");
			isCorrect = false;
		}
		if ( $("#expireDate").val() == "" ){
			alert("请输入期间 迄");
			isCorrect = false;
		}
		if ( $("#giveBonusUpload").val() == "" ){
			alert("请上传檔案");
			isCorrect = false;
		}
		if( $("input:radio:checked[name='budget']").length==0) {
			alert("请选取预算归属");
			isCorrect = false;
		}
		return isCorrect;
	}

</script>
<s:actionerror/>
<s:actionmessage/>
<s:fielderror />
<s:form action="save.do" method="post" id="formObj" enctype="multipart/form-data">
<h1>积分发送</h1>
<p><b>名称：</b><s:textfield id="name" name="name" maxlength="20" /></p>
<p><b>叙述：</b><s:textfield id="description" name="description"/></p>
<p><b>期间 起：</b>
<s:date name="%{startDate}" format="yyyy-MM-dd" var="fmtStartDate"/>
<input type="text" name="startDate" id="startDate" value="${fmtStartDate}" size="10" readonly="readonly"/>
<select id="startTime" name="startTime">			
	<c-rt:forEach begin="0" end="23" var="t1">
	<c-rt:if test="${t1<10}">
	<c-rt:set value="0${t1}:00" var="sTime"></c-rt:set>
	</c-rt:if>
	<c-rt:if test="${t1>=10}">
	<c-rt:set value="${t1}:00" var="sTime"></c-rt:set>
	</c-rt:if>
	<option value="${sTime}" <c-rt:if test="${sTime==startTime}">selected</c-rt:if>>${sTime}</option>
	</c-rt:forEach>
</select>
</p>
<p><b>期间 迄：</b>
<s:date name="%{expireDate}" format="yyyy-MM-dd" var="fmtEndDate"/>
<input type="text" name="expireDate" id="expireDate" value="${fmtEndDate}" size="10" readonly="readonly"/>
<select id="expireTime" name="expireTime">
	<c-rt:forEach begin="0" end="23" var="t2" >
	<c-rt:set var="t3">${23-t2}</c-rt:set>	
	<c-rt:if test="${t3<10}">
	<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
	</c-rt:if>
	<c-rt:if test="${t3>=10}">
	<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
	</c-rt:if>
	<option value="${eTime}" <c-rt:if test="${eTime==expireTime }">selected</c-rt:if>>${eTime}</option>
	</c-rt:forEach>
</select>		
</p>
<!-- 
<p><b>金额：</b>
<s:textfield id="trxAmount" name="trxAmount"/></p> -->
<p><b>档案：</b><s:file id="giveBonusUpload" name="giveBonusUpload"/><span id="resText" class="msg rn" style="display:none;"></span>
<a href="${docUrl}">范例下载</a>
</p>
<s:hidden id="uploadFileName" name="uploadFileName"/>
<p><b>发EMAIL：</b>
		<input type="radio" value="Y" id="sendMail" name="sendMail">
		<label>是</label>
		<input type="radio" value="N" checked="checked" id="sendMail" name="sendMail">
		<label>否</label>
		</p>
<p><b>预算归属：</b>
	<s:radio list="menuBudget.options" name="budget" listValue="value.name"/>
	<span id="budgetText" class="msg rn" style="display:none;"></span>
</p>
<div class="f-link">
	<a href="#" id="saveData">存档</a>
</div>
</s:form>

<c:if test="${importResult != null}">
<BR/> 上传成功，处理明细如下：
<BR/> 上传资料笔数： ${importResult.dataCount}笔。
<BR/> 成功处理笔数： ${importResult.successCount}笔。
<BR/> 共产生积分： ${importResult.totalGiveBouns}积分。
</c:if>
